# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=wolfssl
pkgver=5.5.1
pkgrel=1
pkgdesc="Lightweight, portable, C-language-based SSL/TLS library"
arch=(loong64 x86_64)
url="https://www.wolfssl.com/"
license=(GPL2)
depends=(glibc)
makedepends=(cmake)
provides=(libwolfssl.so)
options=(debug)
source=(
  $pkgname-$pkgver-stable.tar.gz::https://github.com/$pkgname/$pkgname/archive/refs/tags/v$pkgver-stable.tar.gz
  https://github.com/$pkgname/$pkgname/releases/download/v$pkgver-stable/$pkgname-$pkgver-stable.tar.gz.asc
  $pkgname-5.5.1-cmake.patch
)
sha512sums=('821bb7b8105d53c614712eb9f7ebb39a5e20f03c1856edad4e4cdaed797f7940fbe7062905d64bd386878abae1ae3275a4b7792db9b1d673f2de5d903b60f32e'
            'SKIP'
            '02e2a6c370b2ad8e737b9d40d435a65babd8ce9c03892e1f1bf484d328f45bda4fe8be82cc051fdcda4946c405f8ea4baa6840d1db5ae54bec0dbc0dcce7da28')
b2sums=('b735beee96bdc9fde6aca5048c732d77bb86ecbe29ba8ad8cd6528fef340859b3017faa4b84e00c476e017dde741e276440408c3ae6fc90d6790961c6ed26001'
        'SKIP'
        '82cee658075ffb8a2e1ebb2b0a8018b7edbacd29727f7aaca026c8d8808e48cfd617c2e22a01601a80d377423f57d7b6c7dc18186c2f59d8a7ab60bf37ce75ff')
validpgpkeys=(
  A2A48E7BCB96C5BECB987314EBC80E415CA29677  # wolfSSL <secure@wolfssl.com>
)

prepare() {
  # -Werror not even once: https://github.com/wolfSSL/wolfssl/issues/5553
  patch -Np1 -d $pkgname-$pkgver-stable -i ../$pkgname-5.5.1-cmake.patch
}

build() {
  cmake \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_BUILD_TYPE=None \
    -DWOLFSSL_CURVE25519=ON \
    -DWOLFSSL_CURVE448=ON \
    -DWOLFSSL_ED25519=ON \
    -DWOLFSSL_ED448=ON \
    -DWOLFSSL_SHA3=ON \
    -DWOLFSSL_REPRODUCIBLE_BUILD=ON \
    -Wno-dev \
    -B build \
    -S $pkgname-$pkgver-stable
  cmake --build build --verbose
}

check() {
  cd build
  ctest --output-on-failure
}

package() {
  DESTDIR="$pkgdir" cmake --install build
  install -vDm 644 $pkgname-$pkgver-stable/{README,ChangeLog}.md -t "$pkgdir/usr/share/doc/$pkgname/"
}
